﻿
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/HT_Layout.cshtml";
}

<div class="box-body">
    <div class="btn btn-success" id="Add">添加尺寸</div>
    <table class="display table table-hover table-bordered datatable" cellspacing="0" width="100%">
        <thead>
            <tr>
                <th>编号</th>
                <th>商品名称</th>
                <th>尺寸</th>
                <th>价格</th>
                <th>操作</th>
            </tr>
        </thead>
    </table>
</div>

@section myScript{
<script>
        var el = $(".datatable");
        var url = serverPath + "HT_Size/GetAll";
        var method = "post";
        var colunm = [
            { data: 'Id' },
            { data: 'GoodsId' },
            { data: 'Size1' },
            { data: 'Price' },
            { data: 'ss' }
        ];
        var datatable = DataTableInit(el, url, method, colunm);

    //添加
    $("#Add").click(function () {
        $("#myModal h3").text("添加商品尺寸");
        $.get(serverPath + "HT_Size/Add", null, function (data) {
            $("#myModal .modal-body").html(data);
        })

        $("#myModal #btnSubmit").click(function () {
            var p = {
                GoodsId: $("#GoodsId").val(),
                Size1: $("#Size1").val(),
                Price: $("#Price").val()
            }
            console.log(p);
            $.post(serverPath + "HT_Size/Add", p, function (result) {
                if (result.Code==200) {
                    layer.msg(result.Message);
                    $("#myModal").modal("hide");
                    datatable.ajax.reload();
                }
            })
        })
        $("#myModal").modal("show");
    })

    //编辑
    function Edit(a) {
        var id = $(a).attr("data-id");
        
        $("#myModal h3").text("修改尺寸");
        $.get(serverPath + "HT_Size/Edit", { id }, function (data) {
            $("#myModal .modal-body").html(data);

            $("#myModal #btnSubmit").on("click", function () {
                var p = {
                    Id: id,
                    GoodsId: $("#GoodsId").val(),
                    Size1: $("#Size1").val(),
                    Price: $("#Price").val()
                }
                $.post(serverPath + "HT_Size/Edit", p, function (result) {
                    if (result.Code == 200) {
                        layer.msg(result.Message);
                        $("#myModal").modal("hide");
                        datatable.ajax.reload();
                    }
                })
            })
            $("#myModal").modal("show");
        })
    }

    function Delete(a) {
        var id = $(a).attr("data-id");
        $.post(serverPath + "HT_Size/Delete", { id }, function (data) {
            if (data.Code == 200) {
                layer.msg(data.Message);
                $("#myModal").modal("hide");
                datatable.ajax.reload();
            }
        })
        //layer.confirm('确定吗?', { icon: 3, title: '提示' }, function (index) {
        //    $.post(serverPath + "HT_Size/Detele", { id }, function (data) {
        //        if (data.Code == 200) {
        //            layer.msg(data.Message);
        //            datatable.ajax.reload();
        //        }
        //        layer.msg(data.Message);
        //    })
        //    layer.close(index);
        //})
    }

</script>    
}